package com.itheima.server.controller;

import com.itheima.server.service.SmallVideoService;
import com.itheima.vo.PageResult;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("/smallVideo")
public class SmallVideoController {

    @Resource
    private SmallVideoService smallVideoService;


    /**
     * 上传小视频
     * @param videoThumbnail
     * @param videoFile
     * @return
     */
    @PostMapping
    public ResponseEntity<String> uploadVideo(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        smallVideoService.uploadVideo(videoThumbnail,videoFile);
        return ResponseEntity.ok("OK");
    }

    /**
     * 获取小视频列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping
    public ResponseEntity<PageResult> downLoadVideo(@RequestParam(defaultValue = "1") Integer page,
                                                    @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pageResult = smallVideoService.downLoadVideo(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }



}
